<template>
  <div style="height:100%">
    <div>{{titleText}}</div>
    <div style="width:100%;height:100%;" :id="id"></div>
  </div>
</template>

<script>
  const echarts = require('echarts');

  export default {
    name: 'lineChart',
    props: {
      titleText: String,
      times:String,
      id:String,
      hasLegend: {
        type:String,
        default: "true"
      }
    },
    mounted () {
      this.$nextTick(() => {
        var dataSourcePie = echarts.init(document.getElementById(this.id));
        const option = {
          tooltip : {
            trigger: 'axis'
          },
          title : {
            subtext: this.times
          },
          legend: {
            data:['二手房','租房','求购','求租']
          },
          toolbox: {
            show : true,
            feature : {
              magicType : {show: true, type: ['line', 'bar', 'stack', 'tiled']}
            }
          },
          calculable : true,

          xAxis: {       //直角坐标系 grid 中的 x 轴

            type: 'category',

            boundaryGap: false,

            data: ['周一', '周二', '周三', '周四', '周五', '周六', '周日']

          },

          yAxis: {       //直角坐标系 grid 中的 y 轴

            type: 'value'

          },

          series: [      //系列列表

            {

              name: '二手房',

              type: 'line',

              stack: '总量',

              data: [120, 132, 101, 134, 90, 230, 210]

            },

            {

              name: '租房',

              type: 'line',

              stack: '总量',

              data: [220, 182, 191, 234, 290, 330, 310]

            },

            {

              name: '求购',

              type: 'line',

              stack: '总量',

              data: [150, 232, 201, 154, 190, 330, 410]

            },

            {

              name: '求租',

              type: 'line',

              stack: '总量',

              data: [320, 332, 301, 334, 390, 330, 320]

            }

          ]
        };
      dataSourcePie.setOption(option);
      if(this.hasLegend=="false") {
        dataSourcePie.setOption({
          legend: {
            data:[]
          },
          series:[{
                name: '二手房',
                type: 'line',
                stack: '总量',
                data: [0, 132, 101, 134, 90, 230, 210]
              },
              {
                name: '租房',
                type: 'line',
                stack: '总量',
                data: [220, 182, 191, 234, 290, 330, 310]
              },
              {
                name: '求购',
                type: 'line',
                stack: '总量',
                data: [150, 232, 201, 154, 190, 330, 410]
              },
              {
                name: '求租',
                type: 'line',
                stack: '总量',
                data: [320, 332, 301, 334, 390, 330, 320]
              }]
        });
      }
        window.addEventListener('resize', function () {
          dataSourcePie.resize();
        });
      });
    }
  };
</script>
